const { ccclass, property } = cc._decorator;
@ccclass
export default class MatchGameSchedulerMgr {
    constructor() {
        super();
        this.ui = null;
        this.clickStartGame = false;
    }

    onLoad() {
        this.onUILoad();
        this._animType =AnimType.NONE;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        super.onLoad();
        this.addButtonListen();
    }

    start() { }

    onUILoad() {
        this.ui = this.node.addComponent(g);
    }

    addButtonListen() {
       UiManager.addButtonListen(this.ui.btn_close, this.clickClose, this);
       UiManager.addButtonListen(this.ui.btn_leave, this.leaveCallback, this);
       UiManager.addButtonListen(this.ui.btn_restart, this.restartCallback, this);
       UiManager.addButtonListen(this.ui.btn_goon, this.goonCallback, this);
       UiManager.addButtonListen(this.ui.btn_music, this.musicTouch, this);
       UiManager.addButtonListen(this.ui.btn_sound, this.audioTouch, this);
       UiManager.addButtonListen(this.ui.btn_shock, this.shakeTouch, this);
    }

    _init() {
        this.refreshView();
    }

    refreshView() {
        this.changeSwitchState(this.ui.music_on, n.getInstance().getMusicState());
        this.changeSwitchState(this.ui.sound_on, n.getInstance().getAudioState());
        this.changeSwitchState(this.ui.shock_on, n.getInstance().getVibratorState());
        this.clickStartGame = false;
    }

    musicTouch() {
        if (n.getInstance().getMusicState()) {
            n.getInstance().closeBg();
            n.getInstance().pauseMusic("bgm", true);
            n.getInstance().pauseMusic("bgm_outSide", true);
        } else {
            n.getInstance().openBg();
            n.getInstance().playMusic("bgm", true, true);
        }
        this.changeSwitchState(this.ui.music_on, n.getInstance().getMusicState());
    }

    audioTouch() {
        n.getInstance().getAudioState() ? n.getInstance().closeAudio() : n.getInstance().openAudio();
        this.changeSwitchState(this.ui.sound_on, n.getInstance().getAudioState());
    }

    shakeTouch() {
        var e = n.getInstance().getVibratorState();
        e ? n.getInstance().closeVibrator() : n.getInstance().openVibrator();
        this.changeSwitchState(this.ui.shock_on, n.getInstance().getVibratorState());
    }

    changeSwitchState(e, t) {
        e.active = t;
    }

    goonCallback() {
        u.reportData("matchgame_click_goon", {
            level: p.gameLevel
        });
        this.hide();
    }

    leaveCallback() {
        u.reportData("matchgame_click_leave", {
            level: p.gameLevel,
            game_time: p.getGameTime()
        });
        l.trigger(s.END_MATCH_GAME, {
            is_tg: 0
        });
        this.hide();
    }

    restartCallback() {
        var e = this;
        c.log("restartCallback,", this.clickStartGame);
        if (1 != this.clickStartGame) {
            this.clickStartGame = true;
            u.reportData("matchgame_click_restart", {
                level: p.gameLevel,
                game_time: p.getGameTime()
            });
            h.matchGameStart(null, function () {
                var t = p.getGameInfo();
                c.log("MatchGameData.getGameInfo", t);
                l.trigger(s.LOAD_MATCH_SCENE, true);
                e.hide();
            }, function () {
                e.hide();
            });
        }
    }

    clickClose() {
        this.hide();
    }

    static prefabUrl = "MatchGameSetPage";
    static className = "MatchGameSetPageCtrl";
}
